<script setup lang="ts">
import { ref } from 'vue';
import { getUserInfo } from '/@/apis/userApi';
import { useRequest } from 'vue-request';
import { useUserId } from '/@/hooks';

const { getUserId } = useUserId();
const untieIsShow = ref(false);
const userInfo = ref(<any>{});
useRequest(getUserInfo, {
  defaultParams: [{ member: getUserId() }],
  onSuccess(data: any) {
    userInfo.value = data;
    let aaa = [];
    for (let index = 0; index < userInfo.value.bankCard.length; index++) {
      let arrLength = userInfo.value.bankCard.length;
      const element = userInfo.value.bankCard[index];
      if (index >= arrLength - 8 && index < arrLength - 4) {
        aaa.push('*');
      } else {
        aaa.push(element);
      }
    }
    userInfo.value.bankCard = aaa.join('');
  },
});
</script>

<template>
  <div class="bank">
    <AppBar back :primary="true" :title="$t('BankAccount')">
      <!-- <template #right>
        <p @click="untieIsShow = !untieIsShow"  class="untie">{{ untieIsShow ? $t("unedit") :  $t("edit")}}</p>
      </template> -->
    </AppBar>
    <div class="bank_content">
      <div class="bank_box" v-if="userInfo.bankCard || userInfo.moneyAddr">
       <div v-if="userInfo.bankUserName">
        <p class="p1">{{ userInfo.bankUserName }}</p>
        <p class="p2">{{ userInfo.bankName }}</p>
       </div>
        <div v-else class="flex_box">
            <div class="icon_box">
              <img :src="$img('me/TRC.png')" />
            </div>
            <p class="p2">{{ $t('TRON TRC20') }}</p>
          </div>
        <p class="p3">{{ userInfo.bankCard || userInfo.moneyAddr }}</p>
        <div class="time_box">
        {{ $YMDHms(userInfo.bankBindTime) }}
          <div class="add_icon">
            <img :src="$img('me/bank-time.png')" />
          </div>
        </div>
      </div>
      <div v-else class="add_bank_box" @click="$router.push('/me/addBank')">
        <div class="add_icon">
          <img :src="$img('me/bank_add.png')" />
        </div>
        <p class="p1">{{ $t('Nobankcard') }}</p>
        <LargePrimaryButton block> {{ '+ ' + $t('AddyourBankAccount') }}</LargePrimaryButton>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.bank {
  .hr {
    height: 30px;
    background: #f8f8f8;
    width: 100%;
  }

  .bank_content {
    padding: 0 30px;

    .bank_box {
      background-image: url('/@images/me/bank-bg.png');
      min-height: 342px;
      margin-top: 40px;
      background-size: 100% 100%;
      padding: 45px 30px;
      color: #fff;
      position: relative;

      .p1 {
        font-size: 26.92px;
        margin-bottom: 18px;
      }

      .p2 {
        color: rgba(255, 255, 255, 0.7);
        font-size: 23.08px;
        margin-bottom:35px;
      }

      .p3 {
        font-size: 34px;
        font-weight: 600;
        letter-spacing: 4px;
      }

      .time_box {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        font-size: 23.08px;
        color: rgb(255, 255, 255,0.5);
        margin-top: 45px;
        .add_icon {
          width: 80.77px;
          height: 46.15px;
          margin-left: 23px;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
      .icon_box {
        width: 80px;
        height: 80px;
        margin-bottom: 15px;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .wallt_address {
        word-break: break-all;
        font-size: 42px;
      }

      .bank_code {
        margin-top: 20px;
        @include align-center;
        justify-content: space-between;

        .code {
          font-size: 42px;
          font-weight: 600;
          word-break: break-all;
        }

        .bank_time {
          font-size: 22px;

          .bold {
            font-weight: 600;
          }
        }
      }
    }

    .add_bank_box {
      @include center;
      flex-direction: column;
      border-radius: 16px;
      color: #4ca335;
      margin-top: 100px;

      .add_icon {
        width: 330px;
        height: 330px;
        margin-bottom: 10px;

        img {
          width: 100%;
          height: 100%;
        }
      }

      .p1 {
        font-size: 40px;
        font-weight: 500;
        color: rgba(255,255,255, 0.65);
        margin-bottom: 98px;
      }
    }
  }
}
</style>
